import java.util.Scanner;

public class Answer2 {
    //买卖股票的最好时机(一)
    //https://www.nowcoder.com/practice/351b87e53d0d44928f4de9b6217d36bb?tpId=230&tqId=39767&ru=/exam/oj
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n=in.nextInt();
        int min=in.nextInt();
        int ret=-1;
        for(int i=1;i<n;i++){
            int out=in.nextInt();

            ret=Math.max(out-min,ret);

            min=Math.min(min,out);
        }

        System.out.println( ret == -1 ? 0 : ret);
    }

}
